import { get, post, put, del } from '@/utils/request';
import type { Menu } from '@/types';
import type { CreateMenuData, UpdateMenuData, GetMenusParams } from './type';

/**
 * 菜单管理 API
 */

// 获取菜单树
export const getMenuTree = () => {
  return get<Menu[]>('/menus/tree');
};

// 获取菜单列表
export const getMenuList = (params?: GetMenusParams) => {
  return get<Menu[]>('/menus', params);
};

// 获取菜单详情
export const getMenuDetail = (id: string) => {
  return get<Menu>(`/menus/${id}`);
};

// 创建菜单
export const createMenu = (data: CreateMenuData) => {
  return post<Menu>('/menus', data);
};

// 更新菜单
export const updateMenu = (data: UpdateMenuData & { id: string }) => {
  const { id, ...rest } = data;
  return put<Menu>(`/menus/${id}`, rest);
};

// 删除菜单
export const deleteMenu = (id: string) => {
  return del(`/menus/${id}`);
};

